package com.itheima.dao;

import com.itheima.pojo.CategoryMenu;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.RequestParam;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface CategoryMenuMapper extends Mapper<CategoryMenu> {

    @Select("select COUNT(1) from t_category_menu where parent_uid=#{uid}")
    int count(@Param("uid") String uid);

    @Select("select * FROM t_category_menu where uid=#{uid}")
    @Results({
            @Result(column = "menu_level",property = "menuLevel"),
            @Result(column = "parent_uid",property = "parentUid"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime"),
            @Result(column = "is_show",property = "isShow"),
            @Result(column = "menu_type",property = "menuType")
    })
    CategoryMenu findById(@Param("uid") String uid);


    @Select("<script>"+"select *from t_category_menu where parent_uid in"
            +"<foreach item='item' index='index' collection='ids' open='(' separator=',' close=')'>"
    +"#{item}"+"</foreach>"+"</script>")
    @Results({
            @Result(column = "menu_level",property = "menuLevel"),
            @Result(column = "parent_uid",property = "parentUid"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime"),
            @Result(column = "is_show",property = "isShow"),
            @Result(column = "menu_type",property = "menuType")
    })
    List<CategoryMenu> selectInIds(@Param("ids") List<String> ids);


    @Select("select MAX(sort) from t_category_menu where menu_level=#{menuLevel}")
    String selectMax(@Param("menuLevel") Integer menuLevel);

}
